//
//  HXFileDetailsViewController.m
//  KD
//
//  Created by ifly on 16/5/13.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXFileDetailsViewController.h"
#import "UIImageView+WebCache.h"

@interface HXFileDetailsViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webview;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *codeLabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height;
@property(nonatomic,strong) HXFileDetailsListModel *data;
@end

@implementation HXFileDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"公文详情";
    self.webview.backgroundColor = self.view.backgroundColor;
    self.automaticallyAdjustsScrollViewInsets = NO;
    [SVProgressHUD showWithStatus:@"正在获取" ];
    [NetworkAPI getFileDetailsWithDocID:self.dataId
                                Success:^(HXFileDetailsModel *result) {
                                    if ([result.code isEqualToString:@"200"]) {
                                        self.data = result.details;
                                        [SVProgressHUD dismiss];
                                        [self setUpRedHeader];
                                        [self.webview loadHTMLString:result.details.FileContent baseURL:nil];
                                    }else{
                                        [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                    }
                                } failure:^(NSError *err) {
                                    [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                }];
}

-(void)setUpRedHeader{
    self.titleLabel.text = self.data.FileTitle;
    if ([GlobalUtil isNilValue:self.data.FileCode]||[GlobalUtil isNilValue:self.data.PicFileName]) {
        self.height.constant = 0;
        self.imageView.hidden = YES;
        self.redView.hidden = YES;
        self.codeLabel.hidden = YES;
        return;
    }
    self.codeLabel.text = self.data.FileCode;
    NSString *url = [@"http://123.234.82.8/news/pic/Title1802.gif" stringByReplacingOccurrencesOfString:@"1802" withString:self.data.PicFileName];
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:url]];
}

@end